import { Base } from '../../utils/base.js';
import { Location } from '../../utils/location.js';
import { Config } from '../../utils/config.js';
var location = new Location();
class RankingModel extends Base {
  constructor() {
    super();
  }

  // 获取所有列表
  getList(param,callback){
    if (param.city){
      this._getRanking(param, callback);
    }else{
      // 根据地理位置获取数据
      location.getLocation({
        success: (res) => {   //用户同意授权
          param['city']=res.ad_info.city
          this._getRanking(param, callback)
        },
        fail: () => {    //用户拒绝授权
          param['city']=Config.city
          this._getRanking(param, callback)
        }
      });
    }
  }

  getListIndex(success,fail){
    this.request({
      url: '/get_ranking_index',
      success: function (res) {
        success && success(res)
      },
      fail: function (res) {
        fail && fail(res)
      }
    })
  }


  // 获取标榜列表
  _getRanking(param,callback){
    this.request({
      url: '/get_ranking',
      data:param,
      success: function (res) {
        callback && callback(res)
      },
      fail: function (res) {
        callback && callback(res)
      }
    })
  }

  // 获取详细
  getInfo(id,callback){
    this.request({
      url: '/get_ranking_info/' +id,
      success: function (res) {
        callback && callback(res)
      },
      fail: function (res) {
        callback && callback(res)
      }
    })
  }
  // 提交预约
  setYuyue(data,callback){
    this.request({
      type:'POST',
      url: '/set_ranking_yuyue',
      data:data,
      success: function (res) {
        callback && callback(res)
      },
      fail: function (res) {
        callback && callback(res)
      }
    })
  }

}
export { RankingModel}  